package com.c.ctgproject.base

import android.app.Application
import android.content.Context
import cn.jpush.android.api.JPushInterface
import com.c.ctgproject.entity.LoginEntityV2
import com.c.ctgproject.mode.MyConstants
import com.c.ctgproject.retrofit.Constants
import com.c.ctgproject.utils.Utils
import com.c.ctgproject.utils.getGson
import com.c.ctgproject.utils.sharedGet
import com.c.ctgproject.utils.userToken
import com.scwang.smartrefresh.layout.footer.ClassicsFooter
import com.scwang.smartrefresh.layout.header.ClassicsHeader

/**
 *作者:LiBW
 *创建日期: 2020/9/1
 *描述: application基类
 */
open class MyBaseApplication : Application() {


    override fun onCreate() {
        super.onCreate()
        context = this
        val t = Utils.getShared2(this, Constants.TOKEN)
        t?.let {
            userToken = it
        }
        //初始化下拉刷新框架smartRefreshLayout显示的文字
        initRefresh()
        //初始化极光推送
        JPushInterface.init(this)
        val codes = sharedGet(MyConstants.MENU_CODES, "") as String
        val data = getGson().fromJson(codes, LoginEntityV2.DataBean::class.java)
        data?.menus?.forEach {
            it.menuCode?.let { code ->
                mMenuList.add(code)
            }
        }
        userId = sharedGet(Constants.USER_Id, -1) as Int
        userName = sharedGet(Constants.USER_Name, "") as String
    }

    companion object {
        val mMenuList = ArrayList<String>()
        var userName = ""
        var userId = -1
        private var context: Application? = null
        fun getContext(): Context {
            return context!!
        }
    }

    private fun initRefresh() {
        //"下拉可以刷新"
        ClassicsHeader.REFRESH_HEADER_PULLING = "下拉可以刷新"
        //"正在刷新..."
        ClassicsHeader.REFRESH_HEADER_REFRESHING = "正在刷新"
        //"正在加载..."
        ClassicsHeader.REFRESH_HEADER_LOADING = "正在加载"
        //"释放立即刷新"
        ClassicsHeader.REFRESH_HEADER_RELEASE = "释放立即刷新"
        //"刷新完成"
        ClassicsHeader.REFRESH_HEADER_FINISH = "刷新完成"
        //"刷新失败"
        ClassicsHeader.REFRESH_HEADER_FAILED = "刷新失败"
        //"上次更新 M-d HH:mm"
        ClassicsHeader.REFRESH_HEADER_UPDATE = "上次更新 M-d HH:mm"
        //"释放进入二楼
        ClassicsHeader.REFRESH_HEADER_SECONDARY = "释放进入二楼"
        //"上拉加载更多"
        ClassicsFooter.REFRESH_FOOTER_PULLING = "上啦加载更多"
        //"释放立即加载"
        ClassicsFooter.REFRESH_FOOTER_RELEASE = "释放立即加载"
        //"正在刷新..."
        ClassicsFooter.REFRESH_FOOTER_LOADING = "正在刷新"
        //"正在加载..."
        ClassicsFooter.REFRESH_FOOTER_REFRESHING = "正在加载"
        //"加载完成"
        ClassicsFooter.REFRESH_FOOTER_FINISH = "加载完成"
        //"加载失败"
        ClassicsFooter.REFRESH_FOOTER_FAILED = "加载失败"
        //"全部加载完成"
        ClassicsFooter.REFRESH_FOOTER_NOTHING = "全部加载完成"
    }
}